###*
# Created by albert on 16/11/30.
###

###*
# Created by albert on 16/10/13.
###
angular.module('wf-utils')
.directive('ngConfirmClick', ['$uibModal',($uibModal) ->
    return {
      priority: 1
      terminal: true
      link: (scope, element, attr) ->
        console.log()
#        msg = attr.ngConfirmClick
        clickAction = attr.ngClick
        element.bind 'click', (event) ->
          modal = $uibModal.open(
            animation: true
            size: 'sm'
            controller: 'ConfirmModalCtrl'
            templateUrl: 'templates/main/modal/confirm-modal.html'
            resolve: items: ->
              { attr: attr }
          )
          modal.result.then (res) ->
            if res
              scope.$eval clickAction
            return
          return
        return

    }
])
angular.module('wf-utils')
.controller 'ConfirmModalCtrl', ($scope, $uibModalInstance, items, $rootScope) ->
  $scope.modalMessage = items.attr.ngConfirmClick or $rootScope['confirmWord'] or '确认要执行该操作吗？'
  # $scope.modalMessage=$scope.modalMessage||'确认要执行该操作吗？';
  $scope.confirmOK = ->
    $uibModalInstance.close true
    return
  $scope.confirmCancel = ->
    $uibModalInstance.dismiss 'cancel'
    return
